package com.hi3v.auth.monitor.resources;

import com.hi3v.auth.monitor.core.LoginRecord;
import com.hi3v.auth.monitor.core.Person;
import com.hi3v.auth.monitor.db.LoginRecordDAO;
import com.hi3v.auth.monitor.db.PersonDAO;
import liquibase.pro.packaged.M;
import org.eclipse.jetty.util.ajax.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/loginRecord")
@Produces(MediaType.APPLICATION_JSON)
public class MonitorResource {

    private static final Logger LOGGER = LoggerFactory.getLogger(HelloWorldResource.class);

    private final LoginRecordDAO loginRecordDAO;

    public MonitorResource(LoginRecordDAO loginRecordDAO) {
        this.loginRecordDAO = loginRecordDAO;
    }



    @POST
    public Response save(final @Context HttpServletRequest request,LoginRecord loginRecord ) {
        LOGGER.info(request.getRemoteHost());
        loginRecordDAO.insert(loginRecord.getAuthKey(),loginRecord.getCompanyName(),loginRecord.getEndDate(),request.getRemoteHost(),loginRecord.getClientIp(),loginRecord.getUserName());
        return Response.ok().build();

    }



}
